package com.learn.elasticsearch.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.learn.elasticsearch.service.BaseSearchService;
import com.mate.cloud.core.response.BaseResponse;
import com.mate.cloud.core.web.controller.AdminBaseController;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping("/search")
public class EsSearchController extends AdminBaseController {

    private final BaseSearchService esSearchService;

    @GetMapping("/test" )
    public BaseResponse test() {
        return successBodyResponse("Search Success");
    }

    /**
     * 全字段模糊查询
     * @param keyword
     * @param page
     * @return
     */
    @ApiOperation(value = "simpleSearch", notes = "simpleSearch")
    @GetMapping("/simpleSearch" )
    public BaseResponse simpleSearch(String keyword, Page page) {
        return successBodyResponse(esSearchService.simpleSearch(keyword,page.getCurrent(),page.getSize()));
    }


    @ApiOperation(value = "查询所有", notes = "查询所有")
    @GetMapping("/allSearch" )
    public BaseResponse allSearch(Page page) {
        return successBodyResponse(esSearchService.searchAll(page.getCurrent(),page.getSize()));
    }

    @ApiOperation(value = "即时检索", notes = "即时检索")
    @GetMapping("/realTimeSearch" )
    public BaseResponse realTimeSearch(String keyword) {
        return successBodyResponse(esSearchService.realTimeSearch(keyword));
    }

}
